package com.hjs.test.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

public class Tmp {
    public static void main(String[] args) {
        String jsonStr = "{\"name\":\"John\",\"age\":30,\"address\":{\"city\":\"New York\",\"country\":\"USA\"}}";
        System.out.println(jsonStr);
        JSONObject jsonObject = JSON.parseObject(jsonStr);
        System.out.println(jsonObject.getString("name"));
        System.out.println(jsonObject.getString("address"));
        // 判断某个深层的Key是否存在
        boolean isExist = jsonObject.containsKey("address.city");
        System.out.println("是否存在address.city键：" + isExist);
        System.out.println(jsonObject.getString("address.country"));
    }
}
